/*
 * Created by JFormDesigner on Thu May 25 23:04:31 CST 2023
 */

package UI;

import Dao.DbConnection;

import java.awt.*;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.*;
import javax.swing.*;

/**
 * @author wxz
 */
public class Charger extends JDialog {
    public Charger(Window owner) throws SQLException {
        super(owner);
        initComponents();
    }

    private void initComponents() throws SQLException {
        // JFormDesigner - Component initialization - DO NOT MODIFY  //GEN-BEGIN:initComponents  @formatter:off
        ResourceBundle bundle = ResourceBundle.getBundle("Gui");
        desktopPane1 = new JDesktopPane();
        button1 = new JButton();
        scrollPane1 = new JScrollPane();
        //数据库配置
        Connection conn = null;
        PreparedStatement pstm = null;
        ResultSet rs = null;

        conn = DbConnection.getConnection();
        String sql = "select * from powerprice";
        assert conn != null;
        pstm = conn.prepareStatement(sql);
        rs = pstm.executeQuery();
        int count = 0;
        while (rs.next()) {
            count++;
        }
        rs = pstm.executeQuery();
        // 将查询获得的记录数据，转换成适合生成JTable的数据形式
        Object[][] info = new Object[count][3];
        String[] title = {"ID","type","price"};
        count = 0;
        while (rs.next()) {
            info[count][0] = Integer.valueOf(rs.getInt("powerId"));
            info[count][1] = rs.getString("powerName");
            info[count][2] = Integer.valueOf(rs.getInt("powerPrice"));

            count++;
        }
        table1 = new JTable(info , title );

        //======== this ========
        setPreferredSize(new Dimension(540, 400));
        setTitle(bundle.getString("charger.this.title"));
        var contentPane = getContentPane();
        contentPane.setLayout(new BorderLayout());

        //======== desktopPane1 ========
        {

            //---- button1 ----
            button1.setText(bundle.getString("charger.button1.text"));
            button1.setFont(new Font("\u534e\u6587\u884c\u6977", Font.PLAIN, 19));
            desktopPane1.add(button1, JLayeredPane.DEFAULT_LAYER);
            button1.setBounds(15, 15, 70, 35);

            //======== scrollPane1 ========
            {
                scrollPane1.setViewportView(table1);
            }
            desktopPane1.add(scrollPane1, JLayeredPane.DEFAULT_LAYER);
            scrollPane1.setBounds(15, 60, 505, 320);
        }
        contentPane.add(desktopPane1, BorderLayout.CENTER);
        pack();
        setLocationRelativeTo(getOwner());
        // JFormDesigner - End of component initialization  //GEN-END:initComponents  @formatter:on
    }

    // JFormDesigner - Variables declaration - DO NOT MODIFY  //GEN-BEGIN:variables  @formatter:off
    private JDesktopPane desktopPane1;
    private JButton button1;
    private JScrollPane scrollPane1;
    private JTable table1;
    // JFormDesigner - End of variables declaration  //GEN-END:variables  @formatter:on
}
